//
//  Radio_Hot_CollectionViewCell.m
//  Time
//
//  Created by dllo on 16/7/23.
//  Copyright © 2016年 司昌宝. All rights reserved.
//

#import "Radio_Hot_CollectionViewCell.h"

@interface Radio_Hot_CollectionViewCell ()

@property (nonatomic,retain) UIImageView *hotImageView;

@property (nonatomic,retain) UILabel *titleLabel;

@property (nonatomic,retain) UILabel *authorLabel;

@property (nonatomic,retain) UILabel *playsLabel;
@end

@implementation Radio_Hot_CollectionViewCell

-(void)dealloc{
    [_model release];
    [super dealloc];
}

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.hotImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.hotImageView];
        [_hotImageView release];
        
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleLabel];
        [_titleLabel release];
        
        self.authorLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.authorLabel];
        [_authorLabel release];
        
        self.playsLabel = [[UILabel alloc] init];
        [self.hotImageView addSubview:self.playsLabel];
        [_playsLabel release];
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    [self.hotImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(0);
        make.right.equalTo(self.contentView.mas_right).offset(0);
        make.top.equalTo(self.contentView.mas_top).offset(0);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-50);
    }];
    
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(0);
        make.right.equalTo(self.contentView.mas_right).offset(0);
        make.top.equalTo(self.hotImageView.mas_bottom).offset(0);
        make.bottom.equalTo(self.hotImageView.mas_bottom).offset(40);
    }];
    
    self.authorLabel.textColor = [UIColor grayColor];
    self.authorLabel.font = [UIFont systemFontOfSize:10.0];
    self.authorLabel.textAlignment = NSTextAlignmentCenter;
    [self.authorLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(0);
        make.right.equalTo(self.contentView.mas_right).offset(0);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(-10);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(0);
    }];
    
    self.playsLabel.textColor = [UIColor whiteColor];
    self.playsLabel.font = [UIFont systemFontOfSize:10.0];
    self.playsLabel.textAlignment = NSTextAlignmentLeft;
    [self.playsLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.hotImageView.mas_left).offset(0);
        make.width.mas_equalTo(100);
        make.bottom.equalTo(self.hotImageView.mas_bottom).offset(0);
        make.height.mas_equalTo(15);
    }];
    
}

-(void)setModel:(HotModel *)model{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [self.hotImageView setImageWithURL:[NSURL URLWithString:model.userimg] placeholderImage:nil];
    self.titleLabel.text = model.title;
    self.authorLabel.text = model.scbUserinfo.uname;
    CGFloat plays = [model.plays integerValue] / 100000.0;
    self.playsLabel.text = [NSString stringWithFormat:@"%.2fm",plays ];
}



@end
